package cn.yunhe.service.impl;

import cn.yunhe.dao.UserMapper;
import cn.yunhe.model.Page;
import cn.yunhe.model.User;
import cn.yunhe.service.IUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by zs on 2017/12/12.
 */
@Service("userService")
public class UserServiceImpl implements IUserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public Page queryLikeUsers(Map<String, Object> cond) {
        Page page = new Page();
        //总记录数
        page.setTotalNum(userMapper.getLikeUsersCount(cond));
        //每页大小


        int pageSize = Integer.parseInt(String.valueOf(cond.get("pageSize")));
        page.setPageSize(pageSize);
        //当前页码
        int curPageNum = Integer.parseInt(String.valueOf(cond.get("pageNum")));
        page.setCurPageNum(curPageNum);
        //总页数
        page.setTotalPage(page.getTotalNum() / pageSize + (page.getTotalNum() % pageSize == 0 ? 0 : 1));
        page.setResult(userMapper.getLikeUsers(cond));

        return page;
    }

    @Override
    public void addUser(User user) {
        userMapper.addUser(user);
    }

    @Override
    public void delUser(User user) {
        userMapper.delUser(user);
    }

    @Override
    public User findUser(User user) {
        return userMapper.findUser(user);
    }

    @Override
    public void updateUser(User user) {
        userMapper.updateUser(user);
    }






    public UserMapper getUserMapper() {
        return userMapper;
    }

    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }
}
